package com.hellpro.lolbox.home.presenter;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.bean.VideoBean;

import java.util.List;

/**
 * Package_Name: com.hellpro.lolbox.home.presenter
 * Description :
 * author: HellPermanent
 * date:  2016/10/20 1:52
 * remarks：
 */
public class HomeListAdapter extends BaseAdapter {
    private  VideoBean mBean;
    private List<VideoBean.DataBean> data;

    public HomeListAdapter(){
    }
      //追加数据的方法
    public void setHomeList(VideoBean bean){

        data = bean.getData();


        notifyDataSetChanged();
    }



    @Override
    public int getCount() {
        return  data==null?0:data.size();
    }

    @Override
    public Object getItem(int position) {
        return data==null?null:data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      Holder mHolder;
        if (convertView==null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_listitem, parent, false);
        mHolder = new Holder();
            mHolder.content = (TextView) convertView.findViewById(R.id.common_video_content);
            mHolder.num = (TextView) convertView.findViewById(R.id.common_video_num);
            mHolder.title = (TextView) convertView.findViewById(R.id.common_video_title);
            mHolder.phtoto = (SimpleDraweeView) convertView.findViewById(R.id.common_video_photo);
            mHolder.readplay = (TextView) convertView.findViewById(R.id.common_video_yuedubofang);
             convertView.setTag(mHolder);
        }
        else {
            mHolder = (Holder) convertView.getTag();
        }

        VideoBean.DataBean dataBean = data.get(position);
        mHolder.num.setText(dataBean.getReadCount());
        if (dataBean.getType().equals("video")){
        mHolder.readplay.setText("播放");}else {
            mHolder.readplay.setText("阅读");
        }

        mHolder.content.setText(dataBean.getContent());
        String photo = dataBean.getPhoto();
        Uri uri =Uri.parse(photo);
        mHolder.phtoto.setImageURI(uri);
        mHolder.title.setText(dataBean.getTitle());
        return convertView;
    }

    private static  class Holder{
           SimpleDraweeView phtoto;
        TextView title;
        TextView content;
        TextView readplay;
        TextView num;
    }
}
